<template>
  <div class="video-page">
    <div class="video-container">
      <video 
        :src="videoUrl" 
        controls 
        autoplay 
        class="video-player"
        @loadedmetadata="onVideoLoaded"
        @error="onVideoError"
      >
        您的浏览器不支持视频播放。
      </video>
    </div>
    <div class="video-info" v-if="videoTitle">
      <h2>{{ videoTitle }}</h2>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
const videoUrl = ref('')
const videoTitle = ref('自我介绍视频')

const onVideoLoaded = () => {
  console.log('视频加载成功')
}

const onVideoError = (error) => {
  console.error('视频加载失败:', error)
  alert('视频加载失败，请检查视频链接是否有效')
}

onMounted(() => {
  // 从路由参数中获取视频URL
  videoUrl.value = route.query.url || ''
  
  if (!videoUrl.value) {
    alert('未提供视频链接')
    return
  }
  
  // 解码URL
  try {
    videoUrl.value = decodeURIComponent(videoUrl.value)
  } catch (error) {
    console.error('URL解码失败:', error)
  }
})
</script>

<style scoped>
.video-page {
  min-height: 100vh;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.video-container {
  width: 100%;
  max-width: 800px;
  position: relative;
}

.video-player {
  width: 100%;
  height: auto;
  max-height: 80vh;
  border-radius: 8px;
  background: #000;
}

.video-info {
  margin-top: 20px;
  text-align: center;
  color: white;
}

.video-info h2 {
  font-size: 24px;
  font-weight: 500;
  margin: 0;
}

@media (max-width: 768px) {
  .video-page {
    padding: 10px;
  }
  
  .video-player {
    max-height: 60vh;
  }
  
  .video-info h2 {
    font-size: 20px;
  }
}
</style>